class Solution:
    def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:
        def bfs(x):
            nonlocal n
            q = deque([x])
            vis = {x}
            while q:
                u = q.pop()
                for v in range(n):
                    if not graph[u][v] or v in vis:
                        continue
                    if v in initial:
                        return 0
                    q.append(v)
                    vis.add(v)
            return len(vis)

        n = len(graph)
        initial.sort()
        mx = ans = -1
        for x in initial:
            cur = bfs(x)
            if cur > mx:
                mx = cur
                ans = x
        return ans
